﻿#include <iostream>
#include <vector>
using namespace std;
int main()
{
    vector<int> v;  //v是存放int类型变量的可变长数组，开始时没有元素
    for (int n = 0; n < 5; ++n)
    {
        v.push_back(n-3);  //push_back成员函数在vector容器尾部添加一个元素
    }
    cout << v[0] << endl;
    cout << v[4] << endl;

    ;  //定义正向迭代器
    int count = 0;
    for (vector<int>::iterator i = v.begin(); i != v.end(); ++i) {  //用迭代器遍历容器
        cout <<"count = " <<count ;
        cout << " *i = " << *i;
        cout<< " v = "<<v[count]<<endl;  //*i 就是迭代器i指向的元素 
        count++;
    }

    cout << "======================" << endl;
    for (vector<int>::iterator i = v.begin(); i != v.end(); ++i) {  //用迭代器遍历容器
        *i =*i+1 ;
    }

    ;  //定义正向迭代器
    count = 0;
    for (vector<int>::iterator i = v.begin(); i != v.end(); ++i) {  //用迭代器遍历容器
        cout << "count = " << count;
        cout << " *i = " << *i;
        cout << " v = " << v[count] << endl;  //*i 就是迭代器i指向的元素
        count++;
    }
    cout << "======================" << endl;

    count = 0;
    for (vector<int>::iterator i = v.begin(); i != v.end(); ++i) {  //用迭代器遍历容器
        *i = *i - 1;
        cout << "count = " << count;
        cout << " *i = " << *i;
        cout << " v = " << v[count] << endl;  //*i 就是迭代器i指向的元素
        count++;
    }
    cout << "======================" << endl;


    //用反向迭代器遍历容器

    for (vector<int>::reverse_iterator j = v.rbegin(); j != v.rend(); ++j)
       cout << *j << " ";


    return 0;
}